//
//  ViewController.m
//  Attention
//
//  Created by niit on 16/2/18.
//  Copyright © 2016年 NIIT. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()<UIAlertViewDelegate,UIActionSheetDelegate>

@property (weak, nonatomic) IBOutlet UILabel *infoLabel;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - 弹出提示框(UIAlertView)
- (IBAction)btn1Pressed:(UIButton *)sender
{
    // 1. 弹出简单提示框
    UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"弹出框标题"  // 标题
                                                        message:@"弹出框信息"  // 信息
                                                       delegate:self         // 代理人(即哪个对象来处理这个UIAlertView对象的事件)
                                              cancelButtonTitle:@"确定"       // 按钮上的文字
                                              otherButtonTitles:nil];        // 更多按钮
    [alertView show];
}

- (IBAction)btn2Pressed:(UIButton *)sender
{
    // 2. 多个按钮的提示框
    UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"弹出窗口2" message:@"中饭吃没？" delegate:self cancelButtonTitle:@"吃了" otherButtonTitles:@"正在吃",@"还没吃",nil];
    [alertView show];
}

- (IBAction)btn3Pressed:(UIButton *)sender
{
    // 3. 带输入框的提示框
    UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"登入" message:@"请输入用户名密码" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定",nil];
    alertView.alertViewStyle = UIAlertViewStyleLoginAndPasswordInput;// UIAlertView对象的样式
    [alertView show];
}

#pragma mark - 弹出操作表(UIActionSheet)
- (IBAction)btn4Pressed:(UIButton *)sender
{
    UIActionSheet *sheet = [[UIActionSheet alloc] initWithTitle:@"小明:一起吃饭吧?"                 // 标题
                                                       delegate:self                              // 代理人
                                              cancelButtonTitle:@"我吃过了,你去吧."                 // cancelButtong标题
                                         destructiveButtonTitle:@"好的,一起去"                     // destructionButton标题
                                              otherButtonTitles:@"一起吃吃KFC",@"一起去吃MC",nil];  // 其他按钮的标题
    [sheet showInView:self.view];
}


#pragma mark - UIAlertViewDelegate Method 弹出框的代理方法
// 作为UIAlertView的代理人，控制器类中编写相应的事件处理方法,都是可选方法，根据需求选择适当的实现

// 当用户点了哪个按钮对应的方法
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
    NSLog(@"用户点了第几个按钮 = %i,按钮的文字信息:%@",buttonIndex+1,[alertView buttonTitleAtIndex:buttonIndex]);
    NSLog(@"弹窗的信息:%@",alertView.title);
    
    if(buttonIndex != alertView.cancelButtonIndex)
    {
        NSString *info = [NSString stringWithFormat:@"用户名:%@ 密码:%@",[alertView textFieldAtIndex:0].text,[alertView textFieldAtIndex:1].text];
        self.infoLabel.text = info;
    }
}

#pragma mark - UIActionSheetDelegate Method 操作表的代理方法
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
    NSLog(@"操作表的标题:%@",actionSheet.title);
    NSLog(@"用户选择了哪一个按钮:%i,%@",buttonIndex,[actionSheet buttonTitleAtIndex:buttonIndex]);
    
    if(buttonIndex == actionSheet.destructiveButtonIndex)
    {
        NSLog(@"用户点了destructiveBtn");
    }
    else if(buttonIndex == actionSheet.cancelButtonIndex)
    {
        NSLog(@"用户点了cancelBtn");
    }
}

@end
